package cn.itzd.config;

import cn.itzd.constant.SystemConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: dada
 * @Version: 1.0
 * @Description: 通用映射配置
 */
@Configuration
public class ResourcesConfig implements WebMvcConfigurer {

    /**
     * 上传文件存储在本地的根路径
     */
    @Autowired
    private PicCommon common;


    /**
     * @Author: dada
     * @param: registry
     * @Return: void
     * @Version: 1.0
     * @Description: http://localhost:8001/profile/2022/9/5/2d645f1e4c40412988a6364bf0d6a0f3.jpg
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        PicCommon.ElPath path = common.getPath();
        /** 本地文件上传路径 */
        registry.addResourceHandler(SystemConstants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + path.getPath());
    }

}
